package com.cw.lang.redis.service.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.TimeUnit;

import com.cw.lang.redis.service.RedisForListService;

import lombok.Getter;
import lombok.Setter;

/**
 * redisTemplate.opsForList()
 *
 * @author chenw
 * @version $$Id: RedisForListServiceImpl.java, v 0.1 2018/11/19 3:33 PM chenw Exp $$
 */
@Getter
@Setter
public class RedisForListServiceImpl<K extends Serializable, V extends Serializable> extends AbstractRedisService<K, V>
    implements RedisForListService<K, V> {

    @Override
    public List<V> range(K key, long start, long end) {
        return getRedisTemplate(key).opsForList()
            .range(key, start, end);
    }

    @Override
    public void trim(K key, long start, long end) {
        getRedisTemplate(key).opsForList()
            .trim(key, start, end);
    }

    @Override
    public Long size(K key) {
        return getRedisTemplate(key).opsForList()
            .size(key);
    }

    @Override
    public Long leftPush(K key, V value) {
        return getRedisTemplate(key).opsForList()
            .leftPush(key, value);
    }

    @Override
    public Long leftPushAll(K key, V... values) {
        return getRedisTemplate(key).opsForList()
            .leftPushAll(key, values);
    }

    @Override
    public Long leftPushAll(K key, Collection<V> values) {
        return getRedisTemplate(key).opsForList()
            .leftPushAll(key, values);
    }

    @Override
    public Long leftPushIfPresent(K key, V value) {
        return getRedisTemplate(key).opsForList()
            .leftPushIfPresent(key, value);
    }

    @Override
    public Long leftPush(K key, V pivot, V value) {
        return getRedisTemplate(key).opsForList()
            .leftPush(key, pivot, value);
    }

    @Override
    public Long rightPush(K key, V value) {
        return getRedisTemplate(key).opsForList()
            .rightPush(key, value);
    }

    @Override
    public Long rightPushAll(K key, V... values) {
        return getRedisTemplate(key).opsForList()
            .rightPushAll(key, values);
    }

    @Override
    public Long rightPushAll(K key, Collection<V> values) {
        return getRedisTemplate(key).opsForList()
            .rightPushAll(key, values);
    }

    @Override
    public Long rightPushIfPresent(K key, V value) {
        return getRedisTemplate(key).opsForList()
            .rightPushIfPresent(key, value);
    }

    @Override
    public Long rightPush(K key, V pivot, V value) {
        return getRedisTemplate(key).opsForList()
            .rightPush(key, pivot, value);
    }

    @Override
    public void set(K key, long index, V value) {
        getRedisTemplate(key).opsForList()
            .set(key, index, value);
    }

    @Override
    public Long remove(K key, long count, Object value) {
        return getRedisTemplate(key).opsForList()
            .remove(key, count, value);
    }

    @Override
    public V index(K key, long index) {
        return getRedisTemplate(key).opsForList()
            .index(key, index);
    }

    @Override
    public V leftPop(K key) {
        return getRedisTemplate(key).opsForList()
            .leftPop(key);
    }

    @Override
    public V leftPop(K key, long timeout, TimeUnit unit) {
        return getRedisTemplate(key).opsForList()
            .leftPop(key, timeout, unit);
    }

    @Override
    public V rightPop(K key) {
        return getRedisTemplate(key).opsForList()
            .rightPop(key);
    }

    @Override
    public V rightPop(K key, long timeout, TimeUnit unit) {
        return getRedisTemplate(key).opsForList()
            .rightPop(key, timeout, unit);
    }

    @Override
    public V rightPopAndLeftPush(K sourceKey, K destinationKey) {
        return getRedisTemplate(sourceKey).opsForList()
            .rightPopAndLeftPush(sourceKey, destinationKey);
    }

    @Override
    public V rightPopAndLeftPush(K sourceKey, K destinationKey, long timeout, TimeUnit unit) {
        return getRedisTemplate(sourceKey).opsForList()
            .rightPopAndLeftPush(sourceKey, destinationKey, timeout, unit);
    }
}
